package com.linewow.xhyy.nihaonew.activity.user;

import android.os.Looper;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.linewow.xhyy.nihaonew.R;
import com.linewow.xhyy.nihaonew.base.BaseActivity;
import com.linewow.xhyy.nihaonew.entity.NiHaoGeneral;
import com.linewow.xhyy.nihaonew.model.AppConstants;
import com.linewow.xhyy.nihaonew.net.api.NiHaoOkgo;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * Created by LXR on 2016/10/27.
 */
public class SignActivity extends BaseActivity {
    @Bind(R.id.toolbar_back_title)
    TextView toolbarBackTitle;
    @Bind(R.id.toolbar_back_left)
    ImageView toolbarBackLeft;
    @Bind(R.id.toolbar_back_right_tv)
    TextView toolbarBackRightTv;
    @Bind(R.id.sign_text)
    EditText signText;

    @Override
    public void initView() {
        super.initView();
        setContentView(R.layout.activity_sign);
        ButterKnife.bind(this);
        toolbarBackRightTv.setVisibility(View.VISIBLE);
        toolbarBackTitle.setText(getString(R.string.title_sign));
        clickHide();
    }

    @Override
    public void initData() {
        super.initData();
        String sign=getIntent().getStringExtra("info");
        signText.setText(sign);

    }

    @Override
    public void initList() {
        super.initList();
    }


    @OnClick({R.id.toolbar_back_left, R.id.toolbar_back_right_tv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.toolbar_back_left:
                finish();
                break;
            case R.id.toolbar_back_right_tv:
                String sign_txt=signText.getText().toString();
                requestInfo(sign_txt);
                break;
        }
    }

    private void requestInfo(String sign_txt) {
        NiHaoOkgo.signInfo(sign_txt)
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {
                        Looper.prepare();
                        showLoading();
                    }
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<NiHaoGeneral<String>>() {
                    @Override
                    public void call(NiHaoGeneral<String> stringNiHaoGeneral) {
                        dismissLoading();
                        mineViewChange();
                        finish();
                    }
                });
    }

    public void mineViewChange(){
        setResult(AppConstants.CONFIGURECODE);
    }

}
